package com.kol.collect.controller.admin;

import com.kol.collect.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.alibaba.fastjson.JSON;

/**
 * Created by liukun on 20/3/6.
 */

@CrossOrigin(origins = "*", maxAge = 3600)
@Controller
@RequestMapping(value = "/admin/user", method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public class SysUserController {

    @Autowired
    private SysUserService userService;

    /**
     * 登录
     * 
     * @param version
     * @param data
     * @return
     */
    @RequestMapping(value = "/{version}/login")
    @ResponseBody
    public String login(@PathVariable("version") String version, @RequestBody(required = false) String data) {
        return JSON.toJSONString(userService.webLogin(data));
    }

    /**
     * 登出
     * 
     * @param username
     * @return
     */
    @RequestMapping(value = "/logout", method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
    public @ResponseBody Object webLogout(@RequestHeader("username") String username) {
        return JSON.toJSONString(userService.logout(username));
    }

}
